package com.security.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserDetailsService {
    @Autowired
    PasswordEncoder pw;

    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
        String pwd = pw.encode("123");

        return new User(userName,pwd, AuthorityUtils.commaSeparatedStringToAuthorityList("admin,normal，ROLE_admin,ROLE_normal"));
    }
}
